<?php

$workers = [];
$workerNum = 3;

for ($i = 0; $i < $workerNum; $i++) {
    $process = new swoole_process("doProcess");
    $pid = $process->start();
    $workers[$pid] = $process; 
}
 
function doProcess(swoole_process $process)
{
    $process->write("PID: $process->pid");
    echo "写入信息:$process->pid $process->callback"; 

}

foreach ($workers as $process) {
    swoole_event_add($process->pipe, function($pipe) use($process)) {
        $data = $process->read();
        echo "接收到: $data \n";
    });
}